var m_tdActive = null;
/*******************************************************
function HowManyDays()
purpose
  To know how many days in a month
  strMonth:which month
  strYear:which year
********************************************************/
 function HowManyDays(strMonth,strYear)
 {  
	var strDate1=strMonth+"-"+"01"+"-"+strYear
	strMonth=parseInt(strMonth,10)+1
	var strDate2=strMonth +"-"+"01"+"-"+strYear	
	var date1=new Date(strDate1)
	var date2=new Date(strDate2)
	var days=(date2 - date1)/24/60/60/1000
	return days;
}

/*******************************************************
function setCalendarPosition()
purpose:
  to place the calendar by the iCoorX and iCoorY of the 
 btnAccNo
 No return 
********************************************************/
function setCalendarPosition()
{
  var iCoorX,iCoorY,strSrc
  iCoorX=0
  iCoorY=0
  strSrc=btnAcctNo;
  while(strSrc.tagName!="BODY")
	  {
	  iCoorX=iCoorX + strSrc.offsetLeft
	  iCoorY=iCoorY + strSrc.offsetTop
	  strSrc=strSrc.parentElement
	  }
  iCoorX=iCoorX-82
  iCoorY=iCoorY+30
  window.divCalendar.style.posTop=iCoorY
  window.divCalendar.style.posLeft=iCoorX
  window.divCalendar.style.visibility="visible"
}

/*******************************************************
function setDaysToCalendar()
purpose
  Set days to the calendar according to the Firstday-Weekday pairs
  strWeekday:Weekday to the Firstday in a month
  strTotalDays:Total days in the month
********************************************************/
function setDaysToCalendar(strWeekday,strTotalDays,strToday)
{
	var i,j,td,count
	count=1
	for(i=3;i<=8;i++)
	{ 
		if(i==3) 
			for(j=0;j<=6;j++)
			{
				td=tblTotalCalendar.rows(i).cells(j);
				if (j<strWeekday)
				{
					td.Active = false;
				}
				else
				{
					if (j == strWeekday && j>0)
					{
						 //tblTotalCalendar.rows(i).cells(j-1).style.borderRightColor = "#e0e3f7";
					}
					td.innerText=count;
					td.style.borderRightColor = "#5661a8";
					if(count==strToday) 
					{
						td.style.backgroundColor = "#8991c8";
						td.Active = true;
						m_tdActive = td;
					}
					else td.Active = false;
					count=count+1;
				}
			}
		else if(count<=strTotalDays) 
			for(j=0;j<=6;j++)
			{
				td=tblTotalCalendar.rows(i).cells(j);
				td.innerText=count;
				if(count==strToday)
				{
					td.style.backgroundColor = "#8991c8";
					td.Active = true;
					m_tdActive = td;
				}
				else td.Active = false;
				count=count+1;        
				if (count>strTotalDays) 
					return true;
			}
	}  
}

/*******************************************************
function WriteNullToCalendar()
purpose
write null to all of the rows and the cells
********************************************************/
function WriteNullToCalendar()
{
	var i, j;
	var td;
	for(i=3; i<tblTotalCalendar.rows.length; i++)
		for(j=0; j<tblTotalCalendar.rows(i).cells.length; j++)
		{
			td = tblTotalCalendar.rows(i).cells(j);
			td.innerText = "";
		}
		return true;
}

/*******************************************************
function WhichDaySelected()
purpose
Found which day is selected by the user
********************************************************/
function WhichDaySelected()
{
	var i,j,td;
	var ls_date;
	for (i=3;i<=8;i++)
		for(j=0;j<=6;j++)
		{
			td = tblTotalCalendar.rows(i).cells(j);
			if(td.Active == true)
			{
				ls_date=td.innerText;
				return ls_date;		   
			}
		}
}  

/*******************************************************
function ResetbgColor()
purpose
Reset the bgColor to the calendar
********************************************************/
function ResetbgColor()
{
	m_tdActive.style.background = "#e0e3f7";
	m_tdActive.Active = false;
	return true;
}  

/*******************************************************
function FormateDate()
purpose
Change the string to Date
********************************************************/
function FormateDate(strYear,strMonth,strDate)
{
	var ls_date
	strMonth=new String(strMonth)
	strDate=new String(strDate)
	if(strMonth.length==1)strMonth="0"+ strMonth
	if(strDate.length==1) strDate="0"+ strDate
	ls_date=strYear+"-"+strMonth + "-" +strDate;
	return ls_date;
}
